package yuan.common;


import com.alibaba.fastjson.JSONObject;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.ImmutableTag;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;

import java.util.ArrayList;
import java.util.List;

public class MyCounter {

//    static final Counter userCounter = Metrics
//            .counter("service_call_total", "serviceCode", "status");

    static final Counter myCounter = Counter.builder("a_service_call_total")
            .tag("serviceCode", "PS10012")
            .tag("status", "OK")
            .description("service call total")
            .register(Metrics.globalRegistry);

    public static Counter create(String name, List<Tag> tags, String desc){
        return Counter.builder("a_service_call_total")
                .tags(tags)
                .description(desc)
                .register(Metrics.globalRegistry);
    }

//    public void processCollectResult() {
//
//        while (true){
//
//            userCounter.increment(1D);
//
//        }
//    }

    public static String test(){
        ArrayList<Tag> list = new ArrayList(){};
        list.add(new ImmutableTag("serviceCode", "BS20023"));
        list.add(new ImmutableTag("status", "FAILED"));
        Counter counter = create("service_call_total", list, "service call total");
        counter.increment();
        counter.increment();
        return JSONObject.toJSONString(counter.measure());
    }

    public static String test2(){
        myCounter.increment();
        return JSONObject.toJSONString(myCounter.measure());
    }

}
